package com.prime.tutorial.moviestore.dao;


import com.prime.tutorial.moviestore.domain.City;
import com.prime.tutorial.moviestore.domain.Country;
import com.prime.tutorial.moviestore.domain.Street;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;
import java.util.List;

@Repository
public class StreetDAOWithJPA extends GenericDAOWithJPA<Street, Long> implements StreetDAO {

    //	@SuppressWarnings("unchecked")
    public List<Street> findByName(String name) {
        Query query = entityManager.createQuery("Select distinct m from Street m where m.name = ?1");
        query.setParameter(1, name);
        return query.getResultList();
//		return getJpaTemplate().find("Select m from Groups m where m.name = ?1",name);
    }

    public List<Street> findWithDevicesInCity(Country country, City city) {

            Query query = entityManager.createQuery("Select distinct st from Street st, City ci, Country co, Location l, Device d where d.location = l.id and l.country = '"+country.getId()+"' and l.city = '"+city.getId()+"' and l.street = st.id");
//            query.setParameter(1, country.getId());
//            query.setParameter(2, city.getId());
            return query.getResultList();
    }   
}